Assignment#8: Embedded Programming

This assignment is about documenting what I learned in Embedded Programming that includes understanding basics of Embedded Programming that includes architectures, memory, peripherals, word size, microcontroller families, packages, group assignment on comparing the performance and development workflows for other architectures and individual assignment on reading the data sheet for my microcontroller, using programmer to program my board to do something, etc. I have documented how I used different programming languages to program different boards including my hello world board, Arduino uno, Raspberry pi pico and ESP32. I am also documenting what went well, what went wrong, how I would do things differently in next assignment and my learning outcomes.

Objectives of Individual Assignment:

- Read the data sheet for your microcontroller.
- Use your programmer to program your board to do something.
- Extra credit: try other programming languages and development environments.

My Hero shots for this week



Click here to go back to the top

Basics of Embedded Programming

Embedded programming is a specific type of programming that supports the creation of consumer facing or business facing devices that don't operate on traditional operating systems the way that full-scale laptop computers and mobile devices do. The idea of embedded programming is part of what drives the evolution of the digital appliances and equipment in today's IT markets. Embedded programming is also known as embedded software development or embedded systems programming.

Some experts define embedded programming as the dominant methodology for microcontroller programming. Essentially, embedded programming involves programming microcontrollers that drive devices. In terms of its practical implementation, embedded programming is useful in the design of software for automotive features, small facilities-handling devices like thermostats, handheld games or other small devices. Embedded programming differs from full OS-based programming because developers have to take into account the limitations and structures of device hardware. This includes the microprocessor and circuitry. Designers will have to use the unique specifications of this hardware, in order to present an embedded programming solution that works. Experts also use the terms microcomputer and microcontroller to describe certain types of embedded programming. Again, this type of programming is an overall designation for development that will help small computers power objects and appliances that may someday be added to the growing Internet of Things, which will feature more of these tiny computers and allowing cars, home security systems, and many other kinds of functional systems and services to become part of the globally connected Internet.

Embedded System

An embedded system is a computer system-a combination of a computer processor, computer memory, and input/output peripheral devices- that has a dedicated function within a larger mechanical or electronic system. It is embedded as part of a complete device often including electrical or electronic hardware and mechanical parts. Because an embedded system typically controls physical operations of the machine that it is embedded within, it often has real-time computing constraints. Embedded systems control many devices in common use today. In 2009 it was estimated that ninety-eight percent of all microprocessors manufactured were used in embedded systems.

Modern embedded systems are often based on microcontrollers (i.e. microprocessors with integrated memory and peripheral interfaces), but ordinary microprocessors (using external chips for memory and peripheral interface circuits) are also common, especially in more complex systems. In either case, the processor(s) used may be types ranging from general purpose to those specialized in a certain class of computations, or even custom designed for the application at hand. A common standard class of dedicated processors is the digital signal processor (DSP).

Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale.

Embedded systems range in size from portable personal devices such as digital watches and MP3 players to bigger machines like home appliances, industrial assembly lines, robots, transport vehicles, traffic light controllers, and medical imaging systems. Often they constitute subsystems of other machines like avionics in aircraft and spacecraft. Large installations like factories, pipelines and electrical grids rely on multiple embedded systems networked together. Generalized through software customization, embedded systems such as programmable logic controllers frequently comprise their functional units. Embedded systems range from those low in complexity, with a single microcontroller chip, to very high with multiple units, peripherals and networks, which may reside in equipment racks or across large geographical areas connected via long-distance communications lines. While embedded systems are computing systems, they can range from having no user interface (UI) - for example, on devices designed to perform a single task - to complex graphical user interfaces (GUIs), such as in mobile devices. User interfaces can include buttons, LEDs (light-emitting diodes) and touchscreen sensing. Some systems use remote user interfaces as well. Click here to read more.

Applications of Embedded systems

Embedded systems are used in a wide range of technologies across an array of industries. Some examples include:

Automobiles: Modern cars commonly consist of many computers (sometimes as many as 100), or embedded systems, designed to perform different tasks within the vehicle. Some of these systems perform basic utility functions and others provide entertainment or user-facing functions. Some embedded systems in consumer vehicles include cruise control, backup sensors, suspension control, navigation systems and airbag systems.

Mobile phones: These consist of many embedded systems, including GUI software and hardware, operating systems (OSes), cameras, microphones, and USB (Universal Serial Bus) I/O (input/output) modules.

Industrial machines: They can contain embedded systems, like sensors, and can be embedded systems themselves. Industrial machines often have embedded automation systems that perform specific monitoring and control functions.

Medical equipment: These may contain embedded systems like sensors and control mechanisms. Medical equipment, like industrial machines, also must be very user-friendly so that human health isn't jeopardized by preventable machine mistakes. This means they'll often include a more complex OS and GUI designed for an appropriate UI.

Structure of Embedded systems

Embedded systems vary in complexity but, generally, consist of three main elements:

Hardware: The hardware of embedded systems is based around microprocessors and microcontrollers. Microprocessors are very similar to microcontrollers and, typically, refer to a CPU (central processing unit) that is integrated with other basic computing components such as memory chips and digital signal processors (DSPs). Microcontrollers have those components built into one chip.

Software and firmware: Software for embedded systems can vary in complexity. However, industrial-grade microcontrollers and embedded IoT systems usually run very simple software that requires little memory.

Real-time operating system: These are not always included in embedded systems, especially smaller-scale systems. RTOSes define how the system works by supervising the software and setting rules during program execution.

In terms of hardware, a basic embedded system would consist of the following elements:

- Sensors: Convert physical sense data into an electrical signal.

- Analog-to-digital (A-D) converters: They change an analog electrical signal into a digital one.

- Processors: They process digital signals and store them in memory.

- Digital-to-analog (D-A) converters: They change the digital data from the processor into analog data.

- Actuators: They compare actual output to memory-stored output and choose the correct one.


How does an Embedded system work?

Embedded systems always function as part of a complete device - that's what's meant by the term embedded. They are low-cost, low-power-consuming, small computers that are embedded in other mechanical or electrical systems. Generally, they comprise a processor, power supply, and memory and communication ports. Embedded systems use the communication ports to transmit data between the processor and peripheral devices - often, other embedded systems - using a communication protocol. The processor interprets this data with the help of minimal software stored on the memory. The software is usually highly specific to the function that the embedded system serves.

The processor may be a microprocessor or microcontroller. Microcontrollers are simply microprocessors with peripheral interfaces and integrated memory included. Microprocessors use separate integrated circuits for memory and peripherals instead of including them on the chip. Both can be used, but microprocessors typically require more support circuitry than microcontrollers. The term system on a chip (SoC) is often used. SoCs include multiple processors and interfaces on a single chip. A system on a chip (SoC) is an integrated circuit (IC) that integrates all components of a computer or other electronic system into a single chip. They are often used for high-volume embedded systems. Some example SoC types are the application-specific integrated circuit (ASIC) and the field-programmable gate array (FPGA).

Often, embedded systems are used in real-time operating environments and use a real-time operating system (RTOS) to communicate with the hardware. Near-real-time approaches are suitable at higher levels of chip capability, defined by designers who have increasingly decided the systems are generally fast enough and the tasks tolerant of slight variations in reaction. In these instances, stripped-down versions of the Linux operating system are commonly deployed, although other OSes have been pared down to run on embedded systems, including Embedded Java, Embedded C and Windows IoT (formerly Windows Embedded).

Characteristics of Embedded systems:

Embedded systems can include the following characteristics:
- The main characteristic of embedded systems is that they are task-specific, typically consisting of hardware, software and firmware.
- They can be embedded in a larger system to perform a specific function, as they are built for specialized tasks within the system, not various tasks.
- They can be either microprocessor-based or microcontroller-based - both are integrated circuits that give the system compute power.
- They are often used for sensing and real-time computing in internet of things (IoT) devices, which are devices that are internet-connected and do not require a user to operate.
- They can vary in complexity and in function, which affects the type of software, firmware and hardware they use.
- They are often required to perform their function under a time constraint to keep the larger system functioning properly.

Basics of Embedded Systems

Architecture

Von Neumann Architecture:

Von Neumann Architecture is a digital computer architecture whose design is based on the concept of stored program computers where program data and instruction data are stored in the same memory. This architecture was designed by the famous mathematician and physicist John Von Neumann in 1945.

The von Neumann architecture- also known as the von Neumann model or Princeton architecture- is a computer architecture based on a 1945 description by John von Neumann, and by others. The document describes a design architecture for an electronic digital computer with these components:
- A processing unit with both an Arithmetic Logic Unit (ALU) and processor registers
- A control unit that includes an instruction register and a program counter
- Memory that stores data and instructions
- External mass storage
- Input and output mechanisms


Harvard Architecture:

Harvard Architecture is the digital computer architecture whose design is based on the concept where there are separate storage and separate buses (signal path) for instruction and data. It was basically developed to overcome the bottleneck of Von Neumann Architecture.

The term originated from the Harvard Mark I relay-based computer, which stored instructions on punched tape (24 bits wide) and data in electro-mechanical counters. These early machines had data storage entirely contained within the central processing unit, and provided no access to the instruction storage as data. Programs needed to be loaded by an operator; the processor could not initialize itself. Click here to read more.



Difference between Von Neumann and Harvard Architecture
 
VON NEUMANN ARCHITECTURE HARVARD ARCHITECTURE
It is ancient computer architecture based on stored program computer concept.It is modern computer architecture based on Harvard Mark I relay based model.
Same physical memory address is used for instructions and data. It consists of common program and code memory.Separate physical memory address is used for instructions and data. This architecture consists of separate program and code memory.
There is common bus for data and instruction transfer.Separate buses are used for transferring data and instruction.
Two clock cycles are required to execute single instruction.An instruction is executed in a single cycle.
CPU can not access instructions and read/write at the same time.CPU can access instructions and read/write at the same time.
Use CISC processor. It is used in personal computers and small computers.Use RISC processor. It is used in micro controllers and signal processing.
Execution of instructions is relatively slow because not possible to fetch code and data simultaneously.Execution of instructions are faster, because fetching of code and data are separate.
Execution of instruction takes more instruction (machine) cycle.Execution of instruction takes less instruction (machine) cycle.
The largest advantages is that it simplifies the chip design because only one memory is accessed.Chip design is complex because of separate memory.
This is no need to have parallelism.This is greater amount of parallelism.

Microcontroller

A microcontroller (MCU for microcontroller unit) is a small computer on a single metal-oxide-semiconductor (MOS) integrated circuit (IC) chip. A microcontroller contains one or more CPUs (processor cores) along with clock, Digital to Analog Converter (DAC), Analog to Digital Converter (ADC), memory and programmable input/output peripherals. Program memory in the form of ferroelectric RAM, NOR flash or OTP ROM is also often included on chip, as well as a small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications consisting of various discrete chips.

The microcontroller is designed for a specific task or to perform the assigned task repeatedly. Once the program is embedded on a microcontroller chip, it can't be altered easily and you may need some special tools to reburn it. As per application, the process is fixed in microcontroller. Hence, the output depends on the input given by the user or sensors or predefined inputs.

The applications easily connect with concepts, so let's find out day to day life examples. e.g. Calculator, Washing Machine, ATM machine, Robotic Arm, Camera, Microwave oven, Oscilloscope, Digital multimeter, ECG Machine, Printer so on and so forth.



In modern terminology, a microcontroller is similar to, but less sophisticated than, a system on a chip (SoC). An SoC may include a microcontroller as one of its components, but usually integrates it with advanced peripherals like a graphics processing unit (GPU), a Wi-Fi module, or one or more coprocessors. Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and other embedded systems. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems. In the context of the internet of things, microcontrollers are an economical and popular means of data collection, sensing and actuating the physical world as edge devices.



Microprocessor

A Microprocessor is an important part of a computer architecture without which you will not be able to perform anything on your computer. It is a programmable device that takes in input performs some arithmetic and logical operations over it and produces the desired output. In simple words, a Microprocessor is a digital device on a chip that can fetch instructions from memory, decode and execute them and give results. The microprocessor is useful in very intensive processes. It only contains a CPU (central processing unit) but there are many other parts needed to work with the CPU to complete a process. These all other parts are connected externally.

Microprocessors are not made for a specific task as well as they are useful where tasks are complex and tricky like the development of software, games, and other applications that require high memory and where input and output are not defined. Let's understand by some daily life examples.

1) Household devices: Complex home security, Home computers, Video game systems and many more.
2) Transportation and Industrial Devices: Automobiles, trains, planes, Computer servers, high tech medical devices, etc.

All the above applications are complex and they need to process all complicated data.


Basics of Microprocessor

A Microprocessor takes a bunch of instructions in machine language and executes them, telling the processor what it has to do. Microprocessor performs three basic things while executing the instruction:

1. It performs some basic operations like addition, subtraction, multiplication, division, and some logical operations using its Arithmetic and Logical Unit (ALU). New Microprocessors also perform operations on floating-point numbers also.

2. Data in microprocessors can move from one location to another.

3. It has a Program Counter (PC) register that stores the address of the next instruction based on the value of the PC, Microprocessor jumps from one location to another and takes decisions.

Difference between microcontroller and microprocessor
 
Function Microcontroller Microprocessor
DefinitionIt is a small system or computer on a single metal oxide semiconductor IC (Integrated Chip). They are used to handle tasks that control one or more external events or systems.A computer processor is a programmable device having ALU (Arithmetic Logic Unit) ,Control unit on a single integrated circuit. Also known as Logic chip.
FeaturesSmaller circuit, ideal for compact systems, lower cost , less power consumption, high clock speed, 8-bit, 16-bit, or 32-bit.Cost is high as compared to Microcontroller, power consumption is high, don't have power saving feature, low clock speed, 32-bit, or 64-bit
ArchitectureComprises of a chip with embedded inside it - CPU, RAM, ROM, Timer, I/O port, and serial bus interface, all on single chip.Comprises of standalone Central Processing Unit (CPU). Memory (RAM & ROM), I/O components, timer are separate and connected externally.
ApplicationsSpecial purpose: Microcontrollers are used in calculators, Gaming machine, Traffic light control, Military applications , Home appliances etc.General purpose: Microprocessor are used in Computers, Smartphones , transportation industry, instrumentation, Office automation and communication etc.
Drawbacks/ LimitationsCan't interface with high power devices, complex structure, can do limited executions parallelly, used in micro equipmentLimited data size, don't support floating point instructions, heats up easily.
ExamplesAltera, Atmel, Cypress Semiconductor, ELAN Microelectronics Corp, EPSON Semiconductor.MC68000 Motorola, AMD, Intel.


Memory

The memory used in embedded systems can be either internal or external. The internal memory of a processor is very limited. For small applications, if this memory is sufficient, there is need to used external memory.

Internal memory: It is found in the same silicon as the processor. It is accessible to the processor without any use of input and output. If the capacity of the internal memory is high, the cost is likely to be more. The advantage of larger memory internal to the chip is that there will be less program swapping, resulting in fast instruction and data access.

External Memory: Separate devices are used to store the program and temporary data. When the program and data are stored in external devices, data access takes more time than it would with internal memory. External devices require additional circuitry to be built around the processor, to generate the addresses for retrieving the memory contents.


Weather external to internal memories can be further classified into following categories:

- Random Access Memory
- Read-Only Memory
- Hybrid Memory

1. Random Access Memory (RAM):

Its a type of memory that can be accessed randomly - that is, a memory location can be accessed without touching other locations. RAM is also called Read-Write Memory, as you can perform both read and write operations on this memory device. RAM are of two types:

- Static RAM (SRAM) : Retains its contents as long as electrical power is being supplied to the device. For Example: The desktop PC contains SRAM, which loses data when power is switched.
- Dynamic RAM (DRAM): DRAM has sort life cycle, typically one fourth of second, even if power is being supplied. Its uses DRAM controller in conjunction with DRAM to refresh the memory periodically They generally have low costs. Handheld computers contains DRAM to store data.

2. Read Only Memory (ROM):

It is a memory device from which the processor can read data but to which it cannot write data. Like CD. The programs and data that needs to be permanently stored are kept in ROM devices. ROM Retains its contents even if power is switched off; therefore it is used to store program codes and any permanent data retained to initialize and operate embedded systems. A varity of ROM devices are available, each with different capabilities:

- Programmable ROM (PROM): It can be programmed only once.
- Erasable Programmable ROM (EPROM): It can be programmed many times. An EPROM programmer is required to program the EPROM chip.

3. Hybrid Memory:

These are of tree types:
- Electrically Erasable Programmable ROM (EEPROM): It is similar to EPROM, but it can be erased electrically by applying an electrical signal to one of the pins.
- Non-Volatile RAM (NVRAM) : It is a SRAM with battery backup so that the contents are not erased even if power is switched off. Its is very expensive but data access through it is fast.
- Flash Memory : It is also a non - volatile memory, fast EEPROM. The main attraction of flash is that it can be erased one block at a time and programmed one bit at a time. Flash memory devices are high density, low cost, fast (to read but not to write), and electrically programmable. It is being extensively used for embedded systems that contain embedded OS and the application program such as handheld computers.

Buses- Data bus, Control bus and Address bus

It understands the need for, and means of, communication between components. In particular, understand the concept of a bus and how address, data and control buses are used. Components communicate with each other using buses. A bus is a set of parallel wires connecting different coomponents. The processor is connected to the main memory by three separate buses. The three types of buses:

Address bus: It is a pathway or a set of parallel wires that carries the location of the data to be read from or written to. An address bus is one directional only - from the processor to the memory or an I/O controller. The number of lines for the address bus determines the maximum number of bits it can carry, and in turn determines the maximum possible memory capacity of the computer. To understand this, think if the postal office only allows 3 digits for house numbers, then the maximum addressable houses will be 999. So, if the computer has a 32-bit bus, the maximum addressable memory locations will be 2^32, which is 4GB, assuming each memory location stores on byte of data.

Data bus: It is a bi-directional pathway or wires that carries data or instructions between computer components. The width of data bus is a key factor in determining the overall computer performance. Typical data bus is 8, 16, 32 or 64 bits wide. If a computer has a word size of 32 but with a 16-bit data bus, then the data bus has to fetch the word twice from the main memory.

Control bus: Control bus is a bi-directional pathway that carries command, timing and specific status information among components. The following are some of the control information a control bus may carry:
- Write to memory
- Read from memory
- Write to I/O port
- Read from I/O port
- Request for data bus
- Grant for data bus
- Sync clock
- reset all components


Word

Word "size" refers to the amount of data a CPU's internal data registers can hold and process at one time. They are used to describe the number of bits processed at a time by a program or operating system. Modern desktop computers have 64-bit words. Computers embedded in appliances and consumer products have word sizes of 8, 16 or 32 bits.

In computing, a word is the natural unit of data used by a particular processor design. A word is a fixed-sized datum handled as a unit by the instruction set or the hardware of the processor. The number of bits or digits in a word (the word size, word width, or word length) is an important characteristic of any specific processor design or computer architecture.

The size of a word is reflected in many aspects of a computer's structure and operation; the majority of the registers in a processor are usually word sized and the largest piece of data that can be transferred to and from the working memory in a single operation is a word in many (not all) architectures. The largest possible address size, used to designate a location in memory, is typically a hardware word (here, "hardware word" means the full-sized natural word of the processor, as opposed to any other definition used).

Modern processors, including embedded systems, usually have a word size of 8, 16, 24, 32, or 64 bits, while modern general purpose computers usually use 32 or 64 bits. Special purpose digital processors, such as DSPs for instance, may use other sizes, and many other sizes have been used historically, including 9, 12, 18, 24, 26, 36, 39, 40, 48, and 60 bits. The slab is an example of a system with an earlier word size. Several of the earliest computers (and a few modern as well) used BCD rather than plain binary, typically having a word size of 10 or 12 decimal digits, and some early decimal computers had no fixed word length at all.


Microcontroller Families

Following are some of the microcontroller families:

8051 (Intel)

8051 manufactured in 1985. This is an 8-bit microcontroller. The width of the register represents the bit number of microcontroller. For example 89C51 has 8-bit register, so 89C51 is 8-bit microcontroller. In this you can store numbers from 0 to 255, in hexadecimal it is represented as 0x00 to 0xFF. Coming to the instruction set 8051 has 250 instructions which take 1 to 4 machine cycles to execute. The speed of the 8051 microcontroller is 1 million instructions per second. 8051 has powerful instruction set; it has commands which perform more complex calculations. The ALU of the 8051 makes computations simple. In 8051 family there is no inbuilt memory bus and A/D converters. 8051 microcontroller has 32 I/O pins, timers/counters, interrupts and UARTs.

AVR (Atmel)

AVR is another member of microcontroller family. It is developed since 1996 by Atmel and acquired by Microchip Technology in 2016. It is an 8-bit RISC (Reduced Instruction Set Computer) architecture microcontroller. The architecture of AVR was developed by Alf-Egil Bogen and Vegard Wollan. AVR derives its name from its developers and stands for Alf-Egil Bogen Vegard Wollan RISC microcontroller, also known as Advanced Virtual RISC. The AT90S8515 was the first microcontroller which was based on AVR architecture however the first microcontroller to hit the commercial market was AT90S1200 in the year 1997.

There are 16-bit and 32-bit microcontrollers also available in the same family. RISC means Reduced Instruction Set Computer. AVR has 140 instructions which are all 1 cycle based instructions. By default AVR microcontrollers operate with the 1 MHz clock cycle. The speed of AVR microcontroller is 12 million instructions per second. AVR family microcontroller has on-chip boot-loader. By this we can program our microcontroller easily without any external programmer. AVR controllers has number of I/O ports, timers/counters, interrupts, A/D converters, USART, I2C interfaces, PWM channels, on-chip analog comparators. The AVR can be classified into four groups: Classic, Mega, Tiny, and special purpose.

1. Classic AVR (AT90Sxxxx): This is the original AVR chip, which has been replaced by newer AVR chips. These are not recommended for new designs.

2. Mega AVR (ATmegaxxxx): These are the most popular ones having good amount of memory (upto 256 KB), higher number of inbuilt peripherals and suitable for moderate to complex applications. These are powerful microcontrollers with more than 120 instructions and lots of different peripheral capabilities, which can be used in different designs. Some of their characteristics are: Program memory: 4K to 256K bytes, Package: 28 to 100 pins, Extensive peripheral set, Extended instruction set: They have rich instruction sets. Examples: ATMEGA328P

XmegaAVR: Used commercially for complex applications, which require large program memory and high speed.

3. Tiny AVR (ATtinyxxxx): Less memory, small size, suitable only for simpler applications. This group have less instructions and smaller packages in comparison to mega family. You can design systems with low costs and power consumptions using the Tiny AVRs. Some of their characteristics are: Program memory: 1K to 8K bytes, Package: 8 to 28 pins, Limited peripheral set, Limited instruction set: The instruction sets are limited. For example, some of them do not have the multiply instruction. Examples: ATTINY24/44/84.

4. Special purpose AVR: The ICs of this group can be considered as a subset of other groups, but their special capabilities are made for designing specific applications. Some of the special capabilities are: USB controller, CAN controller, LCD controller, Zigbee, Ethernet controller, FPGA, and advanced PWM.



PIC (Programmable interface controller)

PIC (Programmable interface controller) microcontrollers are basically RISC microcontroller. PIC microcontroller was developed in 1993 by Microchip Technology. It is based on Harvard memory architecture. They are available in 3 different architectures. Those are 8-bit, 16-bit and 32-bit microcontrollers. PIC has nearly 40 instructions which all are take 4 clock cycles to execute. The speed of the PIC controller is 3 million instructions per second.

The programming part of the PIC microcontroller is very hard. So those who entering into embedded world freshly this is not preferable for them. It has on-chip peripherals like SPI, ADC, I2C, UART, analog comparator, internal RC oscillator, in-system programmability, etc. PIC microcontrollers are used in different new applications such as smartphones, audio accessories, computer control systems, alarm systems, embedded systems, etc. There are many PICs available in the market ranging from PIC16F84 to PIC16F887. The 8-bit PIC microcontroller is classified into four types on the basis of internal architecture such as Base Line PIC, Mid Range PIC, Enhanced Mid Range PIC and PIC18.

Microcontroller Packaginig

IC packaging refers to the material that contains a semiconductor device. The package is a case that surrounds the circuit material to protect it from corrosion or physical damage and allow mounting of the electrical contacts connecting it to the printed circuit board (PCB).

Why is IC packaging important? The packaging of an integrated circuit is as important as the integrated circuit, the semiconductor device within. The packaging mainly serves three purposes - first, it protects the semiconductor circuit from physical impairment or damage. Secondly, it protects the circuit from corrosion. Finally and most important, it decides how electrical contacts are laid out from the semiconductor device over a PCB. This is an important consideration for both IC designing as well as PCB designing. Like how the connections are organized in an IC, how they are laid out using a standard IC package must be coherent with the application and various use cases of the respective IC. Following are some of the packagings of microcontrollers:


How to select Microcontroller for your application?

The following are some of the important factors to look at when selecting a microcontroller including the Architecture, the memory, Interfaces and I/O real estate among others. Selecting the right microcontroller for a project, will continue to be a problem, every hardware designer will have to solve and while there are few more factors that may influence the choice of microcontroller, the factors mentioned below are the most important.

1. Application: The first thing to do before selecting a microcontroller for any project is to develop a deep understanding of the task for which the microcontroller based solution is to be deployed. A technical specification sheet is always developed during this process and it will help to determine the specific features that the microcontroller which will be used for the project. A good example of how the application/use of the device determines the microcontroller to be used is exhibited when a microcontroller with a floating point unit is adopted for the design of a device that will be used to perform operations involving a lot of decimal numbers.

2. Select Microcontroller Architecture: Select between Von Neumann and Harvard Architecture. The von Neumann architecture features the use of the same bus to transmit data and fetch instruction sets from the memory. Therefore data transfer and instruction fetch cannot be performed at the same time and are usually scheduled. The Harvard architecture on the other hand features the use of separate buses for the transmission of data and fetching of instructions. Each of these architectures comes with its own advantage and disadvantage. The Harvard architecture for instance are RISC (Reduced instruction Set) computers and are thus able to perform more instructions with lower cycles than the CISC (Complex instruction Set) computers which are based on the von Neumann architecture. One important advantage of the Harvard (RISC) based microcontrollers is the fact that the existence of different buses for data and instruction set enables the separation of the memory access and the operations of the Arithmetic and logic unit (ALU). This reduce the amount of computational power required by the microcontroller and it leads to reduced cost, low power consumption and heat dissipation which makes them ideal for the design of battery operated devices. Many ARM, AVR and PIC Microcontrollers are based on the Harvard architecture. Example of microcontrollers that use the Von Neumann architecture include 8051, zilog Z80 among others.

3. Bit Size: A microcontroller can either be 8bits, 16bits, 32bits and 64bits which is the current maximum bit size possessed by a microcontroller. The bit size of a microcontroller represents the size of a "word" used in the instruction set of the microcontroller. This means in a 8-bit microcontroller, the representation of every instruction, address, variable or register takes 8-bit. One of the key implications of the bit size is the memory capacity of the microcontroller. In an 8-bit microcontroller for example, there are 255 unique memory locations as dictated by the bit size while in a 32-bit microcontroller, there are 4,294,967,295 unique memory locations, which means the higher the bit size, the higher the number of unique memory locations available for use on the microcontroller. Manufacturers these days however, are developing ways to provide access to more memory location to smaller bit size microcontrollers via paging and addressing, so that 8bits microcontroller become 16bits addressable but this tends to complicate programming for the embedded software developer.

The effect of bit size is probably more significantly experienced when developing the firmware for the microcontroller especially for arithmetic operations. The various data types have different memory size for different microcontroller bit size. For example, using a variable declared as an unsigned integer which due to the data type will require 16bits of memory, in codes to be executed on an 8bit microcontroller will lead to the loss of the most significant byte in the data which at times may be very important to the achievement of the task for which the device on which the microcontroller is to be used, was designed. It is thus important to select a microcontroller with a bit size that matches that of the data to be processed. It is probably important to note that most application these days are between 32bits and 16 bits microcontrollers due to the technological advancements incorporated on these chips.

4. Interfaces for Communication: Communication between the microcontroller and some of the sensors and actuators that will be used for the project might require the use of an interface between the microcontroller and the sensor or actuator to facilitate the communications. Take for instance to connect an analog sensor to a microcontroller will require that the microcontroller has enough ADC (analog to digital converters) or as I mentioned earlier, varying the speed of a DC motor may require the use of PWM interface on the microcontroller. So it will be important to confirm that the microcontroller to be selected has enough of the interfaces required including UART, SPI, I2C among others.

5. Operating Voltage: The Operating voltage is the voltage level at which a system is designed to operate. It is also the voltage level to which certain characteristics of the system are related. In hardware design the operating voltage at times determine the logic level at which the microcontroller communicates with other components that makes up the system.

The 5V and 3.3V voltage level are the most popular operating voltage used for microcontrollers and a decision should be made on which of these voltage level will be used during the process of developing the technical specification of the device. Using a microcontroller with a 3.3V operating voltage in the design of a device where most of the external components, sensors and actuators will be operating on a 5V voltage level will not be a very smart decision as there will be a need to implement logic level shifters or converters to enable the exchange of data between the microcontroller and the other components and this will increase the cost of manufacturing and the overall cost of the device unnecessarily.

6. Number of I/O Pins: The number of general or special purpose input/output ports and (or) pins possessed by a microcontroller is one of the most important factors that influences the choice of microcontroller. If a microcontroller were to have all of the other features mentioned in this article but doesn't have enough IO pins as required by the project, it cannot be used. It is important that the microcontroller has enough PWM pins for instance, to control the number of DC motors whose speed will be varied by the device. While the number of I/O ports on a microcontroller can be expanded by the use of shift registers, it cannot be used for all kind of applications and increases the cost of the devices in which it is used. Therefore, it is better to ensure the microcontroller to be selected for the design has the required number of general and special purpose I/O ports for the project.

One other key thing to keep in mind when determining the amount of general or special purpose I/O pins required for a project, is the future improvement that may be done to the device and how those improvements may affect the number of I/O pins required.

7. Memory Requirements: There are several types of memory associated with a microcontroller that are designer should look out for when making a selection. The most important ones are the RAM, ROM and EEPROM. The amount of each of these memories needed might be difficult to estimate until its being used but judging on the amount of work required of the microcontroller, predictions can be made. These memory devices mentioned above form the data and program memory of the microcontroller.

The program memory of the microcontroller stores the firmware for the microcontroller so when power is disconnected from the microcontroller, the firmware is not lost. The amount of program memory needed depends on the amount of data like libraries, tables, binary files for images etc that are needed for the firmware to work correctly.

The data memory on the other hand is used during run time. All variables and data generated as a result of processing among other activities during run-time is stored in this memory. Thus, the complexity of computations that will occur during run-time can be used to estimate the amount of data memory needed for the microcontroller.

8. Package Size: The package size refers to the form factor of the microcontroller. Microcontrollers generally come in packages ranging from QFP, TSSOP, SOIC to SSOP and the regular DIP package which makes mounting on breadboard for prototyping easy. It's important to plan ahead of the manufacturing and envisage which package will be best.

9. Power Consumption: This is one of the most important factors to consider when selecting a microcontroller especially when it is to be deployed in a battery powered application like IoT devices where it is desired that the microcontroller be as low power as possible. The datasheet of most microcontrollers contain information on several hardware and (or) software based techniques that can be used to minimize the amount of power consumed by the microcontroller in different modes. Ensure the microcontroller you are selecting satisfies the power requirements for your project.

10. Support for Microcontroller: It's important the microcontroller you choose to work with has enough support including; code samples, reference designs and if possible a large community online. Working with a microcontroller for the first time might come with different challenges and having access to these resources will help you overcome them quickly. While using latest microcontrollers because of those cool new features it came with is a good thing, it is advisable to ensure that the microcontroller has been around for at least 3-4 months to ensure most of the early problems that may be associated with the microcontroller would have been resolved since various customers would have done plenty of testing of the microcontroller with different applications.

It is also important to select a microcontroller with a good evaluation kit, so you can quickly start building prototype and test out features easily. The evaluation kits are a good way to acquire experience, get familiar with the tool chain used for development, and save time during the development of the device.

Example 1

Example 2

Click here to go back to the top

Group Assignment Brief

This assignment is about documenting what we learned in Embedded programming week that includes understanding the data sheets of microcontrollers, compare the performance and development workflows for other architectures. We used ESP32 board, which is from Xtensa family of microcontrollers. We used micropython to program the ESP32 through Thonny IDE to blink an inbuilt as well as external LED attached to this board

Objectives of the Group Assignment:

- Understanding the data sheets of microcontrollers
- Compare the performance and development workflows for other architectures



Comparison of Microcontroller Architectures
Parameters Arduino Uno ESP 32 ESP8266 Raspberry Pi Pico
MicrocontrollerATMega328PESP32ESP8266RP2040
CoreSingle coreDual coreSingle coreDual core
Architecture8 bit RISC32 bit LX6 with 600 DMIPS32 bit LX10632 bit ARM cortex M0+
Clock Speed16 MHzUp to 240MHzUp to 160MHzUp to 133MHz
Operating voltage5v3.3v3.3v3.3v
GPIO Voltage5v3.3v3.3v3.3v
Digital pins14361626
PWM pins6321616
Analog pins61513
SPI/I2C/UART/I2s1/1/14/2/2/22/1/2/22/2/2
WifiNOYESYESNO
BluetoothNOYESNONO
Built-in sensorNOTouch, Temperature, Hall Effect sensorsNOTemperature sensor
Programming LanguageArduino IDE, C/C++Arduino IDE, C/C++, Micro PythonArduino IDE, C/C++, Micro Python, JavascriptC/C++, Micro Python
On board Programming LEDD13 pinD2 pinD0 pinGP25 pin
Flash32KB4MB4MB2MB
RAM264KB520KB128KB264KB
EEPROM1KBNO520BNO
AdvantagesBest for beginners and Pro because there are so many modules and library.Best for IoT projectsBest for IoT projectsBest for Machine Learning

Click here to read more about our Group Assignment.

Click here to go back to the top

Individual Assignment

Reading Data sheets

A data sheet, data-sheet, or spec sheet is a document that summarizes the performance and other characteristics of a product, machine, component (e.g., an electronic component), material, subsystem (e.g., a power supply), or software in sufficient detail that allows a buyer to understand what the product is and a design engineer to understand the role of the component in the overall system. Typically, a data sheet is created by the manufacturer and begins with an introductory page describing the rest of the document, followed by listings of specific characteristics, with further information on the connectivity of the devices. In cases where there is relevant source code to include, it is usually attached near the end of the document or separated into another file. Data sheets are created, stored, and distributed via product information management or product data management systems. Click here to read more. Following is my understanding after datasheeet of ATTiny44 microcontroller.


The Atmel ATtiny24/44/84 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. The Atmel ATtiny24/44/84 provides the following features:
- It's operating voltage is 2.7 - 5.5V and it is a low power consumption microcontroller, I can use it in applications, which will even run on batteries or solar systems.
- 2/4/8K bytes of in-system programmable flash: 2K bytes for ATtiny24, 4K bytes for ATtiny44, 8K bytes for ATtiny84
- 128/256/512 bytes EEPROM: 128 bytes for ATtiny24, 256 bytes for ATtiny44, 512 bytes for ATtiny84
- 128/256/512 bytes SRAM: 128 bytes for ATtiny24, 256 bytes for ATtiny44, 512 bytes for ATtiny84
- It is 14-pin SOIC, 20-pin QFN/MLF (package): Twelve programmable I/O lines
- 32 general purpose working registers
- An 8-bit Timer/Counter with two PWM channels
- A 16-bit Timer/Counter with two PWM channels
- Internal and external interrupts
- An 8-channel 10-bit ADC
- A programmable watchdog timer with internal oscillator, internal calibrated oscillator, and three software selectable power saving modes.

Pin Descriptions for ATtiny24/44/84

1. VCC: Supply voltage.

2. GND: Ground.

3. Port B: (PB3:PB0)
Port B is a 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability except PB3 which has the RESET capability. To use pin PB3 as an I/O pin, instead of RESET pin, program ('0') RSTDISBL fuse. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running.

4. RESET
Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running and provided the reset pin has not been disabled. Shorter pulses are not guaranteed to generate a reset. The reset pin can also be used as a (weak) I/O pin.

3. Port A (PA7:PA0)
Port A is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port A pins that are externally pulled low will source current if the pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port A has alternate functions as analog inputs for the ADC, analog comparator, timer/counter.


Pin connections in my Hello-world Board




Pin addresses- Binary and Hexadecimal

Below is a method I have written to identify binary and hexadecimal addresses of microcontroller pins.


Below is an excel sheet converter developed by one of my Fab lab colleagues Kiran sir to find out binary and hexadecimal addresses of microcontroller pins. Thank you, Kiran sir for making this available for everyone to use.


Embedded Programming

I did embedded programing for different boards using different programing languages and IDEs:


1. Arduino (ATmega328P) with Embedded C- Arduino IDE


Inbuilt LED in arduino board is connected to pin PB5. The binary address of PB5 pin is 0B00100000 and the Hexadecimal address is 0X20, so I used these addresses to blink this LED as shown in the video below.

Click here to see/copy the "Arduino_EmbdC_Binary" program.

Click here to see/copy the "Arduino_EmbdC_Hexadecimal" program.

Or click here to download all the programs


2. Hello-world (ATtiny44) with Arduino C and Embedded C - Arduino IDE



Click here to see/copy the "Helloworld_ArduinoC" program.

Click here to see/copy the "Helloworld_EmbdC_Binary" program.

Click here to see/copy the "Helloworld_EmbdC_Hexadecimal" program.

Or click here to download all the programs

In Hello-world board, LED1 is connected to PB2 and LED2 to PA7 pins on the microcontroller, so I used arduino pin numbers to blink this LED through arduino C language and binary and hexadecimal addresses of these pins for programming through embedded c as shown in the video below.



3. Hello-world (ATtiny44) with Embedded C - through avrdude

I did embedded c programming of ATtiny44 through avrdude as shown in steps and video below.









Click here to see/copy the "embedded.c" program.

Click here to see/copy the "embedded.c.make" file.

Or click here to download all the programs


4. ESP32 with micro-python: through Thonny IDE

I did programming for blinking LED with ESP32 (inbuilt and externally connected to the board) though micro-python through Thonny IDE as shown the video below.

Click here to see/copy the "ESP32 Inbuilt LED blink" program.

Click here to see/copy the "ESP32 additional LED blink" program.

Or click here to download all the programs



5. Raspberry pi- Pico with micro-python: through Thonny IDE

I did programming for blinking LED with Raspberry pi- Pico (inbuilt) though micro-python through Thonny IDE as shown the video below.

Click here to see/copy the "Raspberry pi pico Inbuilt LED blink" program.

Or click here to download all the programs


Selecting Micro-controller for my Final Project

Since I am working on a project of IoT based smart storage system for post-harvest onions, I would be needing to measure and monitor different parameters like temperature, humidity, etc. and send the data to the farmer using wifi or bluetooth devices, I am selecting ESP32 microcontroller for my final project. Following are the points I learned from the ESP32 datasheet for the same:







Click here to go back to the top

Download Original Files

Click here to download all program files.

Click here to go back to the top

What went well

In group assignment- We went through the datasheets of ESP32, ATtiny44, Raspberry pi pico and also compared them. We could program all of these microcontrollers.
In individual assignment- I learned multiple programming languages and also how to use different platforms, IDEs to program the microcontrollers.

What went wrong

In group assignment- We were not able to understand how to program external additional LED to the ESP32, however, it worked well later.
In individual assignment- I used to forget to add .py extenstion at the end of the micro-python program and I had faced issues because of that.

Click here to go back to the top

What I would do differently

- I would learn programming different microcontroller through different languages.
- I would learn pure c programming language.

Learning Outcomes

- I learned basics of embedded systems that I always thought to be too difficult for me to learn.
- I learned how to identify binary and hexadecimal addresses of pins on the microcontroller.
- I learned how program the boards using different languages through platforms.
- I learned how to read the datasheets of microcontrollers.
- I learned that embedded programming is fun and I am looking forward to use more of them in my next assignments on make a machine, input and output devicesand also in my final project.

Click here to go back to the top